|
Generics are a facility of generic programming that were added to the Java programming language in 2004 within J2SE 5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety."〔(Java Programming Language )〕 This feature specifies the type of objects stored in a Java Collection. In 1998, Philip Wadler created Generic Java, an extension to the Java language to support generic types.〔(GJ: Generic Java )〕 Generic Java was incorporated, with the addition of wildcards, into the official Java language version J2SE 5.0. ==Hierarchy and classification== According to ''Java Language Specification'':〔(Java Language Specification, Third Edition ) by James Gosling, Bill Joy, Guy Steele, Gilad Bracha – Prentice Hall PTR 2005〕 *A type variable is an unqualified identifier. Type variables are introduced by generic class declarations, generic interface declarations, generic method declarations, and by generic constructor declarations. *A class is generic if it declares one or more type variables. These type variables are known as the type parameters of the class. It defines one or more type variables that act as parameters. A generic class declaration defines a set of parameterized types, one for each possible invocation of the type parameter section. All of these parameterized types share the same class at runtime. *An interface is generic if it declares one or more type variables. These type variables are known as the type parameters of the interface. It defines one or more type variables that act as parameters. A generic interface declaration defines a set of types, one for each possible invocation of the type parameter section. All parameterized types share the same interface at runtime. *A method is generic if it declares one or more type variables. These type variables are known as the formal type parameters of the method. The form of the formal type parameter list is identical to a type parameter list of a class or interface. *A constructor can be declared as generic, independently of whether the class that the constructor is declared in is itself generic. A constructor is generic if it declares one or more type variables. These type variables are known as the formal type parameters of the constructor. The form of the formal type parameter list is identical to a type parameter list of a generic class or interface. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Generics in Java」の詳細全文を読む スポンサード リンク
|